package com.example.springboot.service.impl;

import com.example.springboot.pojo.Announcement;
import com.example.springboot.pojo.User;
import com.example.springboot.service.AnnouncementService;
import com.example.springboot.mapper.AnnouncementMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AnnouncementServiceImpl implements AnnouncementService {
    @Autowired
    private AnnouncementMapper announcementMapper;
    @Override
    public void create(Announcement announcement) {
        announcementMapper.create(announcement);
    }
    @Override
    public void delete(Integer id) {
        announcementMapper.delete(id);
    }
    @Override
    public void update(Announcement announcement) {
        announcementMapper.update(announcement);
    }


    @Override
    public List<Announcement> findAll() {
        return announcementMapper.findAll();
    }

    @Override
    public List<Announcement> findByTitle(String title) {
        return announcementMapper.findByTitle(title);
    }

    @Override
    public PageInfo<Announcement> selectPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Announcement> list = announcementMapper.findAll();
        return PageInfo.of(list);
    }

    @Override
    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids) {
            announcementMapper.delete(id);
        }
    }

    @Override
    public Announcement findById(Integer id) {
        return announcementMapper.findById(id);
    }


}
